package com.flannery.learningandroid.edittag

import android.os.Bundle
import android.widget.CompoundButton
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.SwitchCompat
import com.flannery.learningandroid.R
import java.util.*

class EditTagActivity : AppCompatActivity() {


    private var editTagView: EditTag? = null

    private var statusSwitchView: SwitchCompat? = null

    private val tagStrings: MutableList<String> =
        ArrayList<String>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_edit_tag)

        editTagView = findViewById(R.id.edit_tag_view) as EditTag
        statusSwitchView = findViewById(R.id.status_switch) as SwitchCompat
        //statusSwitchView!!.setOnCheckedChangeListener(this@EditTagActivity)
        for (i in 0..199) {
            tagStrings.add("test$i")
        }
        //Set tag add callback before set tag list
        editTagView!!.setTagAddCallBack {
            if ("test1" == it) {
                false
            } else {
                true
            }
        }

        editTagView!!.setTagDeletedCallback {
            Toast.makeText(this, it, Toast.LENGTH_SHORT).show()
        }

//        editTagView!!.setTagAddCallBack(object : EditTag.TagAddCallback {
//            fun onTagAdd(tagValue: String): Boolean {
//                return if ("test1" == tagValue) {
//                    false
//                } else {
//                    true
//                }
//            }
//        })
//        editTagView!!.setTagDeletedCallback(object : EditTag.TagDeletedCallback {
//            fun onTagDelete(deletedTagValue: String?) {
//                Toast.makeText(this@MainActivity, deletedTagValue, Toast.LENGTH_SHORT).show()
//            }
//        })
        editTagView!!.tagList = tagStrings
        editTagView!!.addTag("hello world!")
        editTagView!!.removeTag("test3")
    }


    fun onCheckedChanged(buttonView: CompoundButton?, isChecked: Boolean) {
        editTagView!!.setEditable(isChecked)
    }
}
